libraries
library(tidyverse)
library(sf)
library(tmap)
library(maptools)
#library(classint)
#library(OpenStreetMap)
library(RColorBrewer)
#library(Sp)
library(rgeos)
library(tmap)
library(tmaptools)
#library(downloader)
library(rgdal)
library(geojsonio)
library(leaflet)
Reference URLs
https://www.ons.gov.uk/methodology/geography/ukgeographies/censusgeography
https://github.com/spacesyntax/OpenMapping
https://www.r-bloggers.com/5-ways-to-subset-a-data-frame-in-r/
https://stackoverflow.com/questions/11562656/calculate-the-mean-by-group
https://geocompr.robinlovelace.net/adv-map.html
https://rstudio.github.io/leaflet/basemaps.html
http://leaflet-extras.github.io/leaflet-providers/preview/index.html
https://rpubs.com/adam_dennett/427207
http://pro.arcgis.com/en/pro-app/help/mapping/layer-properties/data-classification-methods.htm
https://github.com/mtennekes/tmap/issues/175
Read Openmapping data
#ssx <- read_csv("/Volumes/ucfnnap/R/Rprojects/ssyntax/OpenMapping-gb-v1_csv/csv/ssx_openmapping_gb_v1.csv") # 2,063,322 observations of 36 variables
Read Omnis data
nom <- read_csv("/Volumes/ritd-ag-project-rd00lq-jamfe87/GIS_Analysis/dataProcessed/nomis_4835.csv") # 4,835 obs.
Create variable ‘lsoa11_cd’ from variable ‘lsoa11_2011’ substract chr 1 to 4 (first 4 characters)
nom <- mutate(nom, lsoa11_cd = substr(lsoa_2011, 1, 9))
Read lsoa codes for London
#lsoa_ldn <- read_csv("/Volumes/ritd-ag-project-rd00lq-jamfe87/GIS_Analysis/dataProcessed/lsoa_ldn.csv") # 4,835 obs.
#class(lsoa_ldn)
Covert dataframe column to vector
#lsoa_ldnV <- as.vector(lsoa_ldn$lsoa_ldn, mode = 'any')
“Subset ssx with London lsoa codes ‘lsoa_ldnV’”
Read SSX dataset for london ‘ssx_ldn.csv’
#ssx_ldn <- ssx[ssx$lsoa11cd %in% lsoa_ldnV,] # 111,582 obs.
#write_csv(ssx_ldn, "/Volumes/ritd-ag-project-rd00lq-jamfe87/GIS_Analysis/dataProcessed/ssx_ldn.csv")
ssx_ldn <- read_csv("/Volumes/ritd-ag-project-rd00lq-jamfe87/GIS_Analysis/dataProcessed/ssx_ldn.csv")
## Parsed with column specification:
## cols(
## .default = col_character(),
## id = col_integer(),
## metres = col_double(),
## meridian_id = col_integer(),
## meridian_gid = col_integer(),
## meridian_code = col_integer(),
## choice2km = col_double(),
## choice2kmrank = col_double(),
## choice2kmlog = col_double(),
## nodecount2km = col_integer(),
## integration2km = col_double(),
## integration2kmrank = col_double(),
## choice10km = col_double(),
## choice10kmrank = col_double(),
## choice10kmlog = col_double(),
## nodecount10km = col_integer(),
## integration10km = col_double(),
## integration10kmrank = col_double(),
## choice100km = col_double(),
## choice100kmlog = col_double(),
## nodecount100km = col_integer()
## # ... with 2 more columns
## )
## See spec(...) for full column specifications.
Calculate mean value for lsoa of choice2kmrank
choice2 <- aggregate(choice2kmrank ~ lsoa11cd, ssx_ldn, mean )
Load LSOA London boundaries geometries
censusb <- read_shape("/Volumes/ucfnnap/made_in_london/GISanalysis/dataRaw/statistical-gis-boundaries-london/ESRI/LSOA_2011_London_gen_MHW.shp")
qtm(censusb)
join1 <- append_data(censusb, choice2, key.shp = "LSOA11CD", key.data = "lsoa11cd", ignore.duplicates = TRUE, ignore.na = TRUE)
join1 <- append_data(join1, nom, key.shp = "LSOA11CD", key.data = "lsoa11_cd", ignore.duplicates = TRUE, ignore.na = TRUE)
names(join1)
## [1] "LSOA11CD" "LSOA11NM" "MSOA11CD"
## [4] "MSOA11NM" "LAD11CD" "LAD11NM"
## [7] "RGN11CD" "RGN11NM" "USUALRES"
## [10] "HHOLDRES" "COMESTRES" "POPDEN"
## [13] "HHOLDS" "AVHHOLDSZ" "choice2kmrank"
## [16] "lsoa_2011" "Count" "Industry percentage"
## [19] "geometry"
# join1SP <- join1 %>%
# st_transform(crs = 4326) %>%
# as("Spatial")
# pal <-colorBin("PuBuGn", join1SP$Count, n=7)
#
# leaflet(join1SP) %>%
# addProviderTiles("Esri.WorldImagery") %>%
# addPolygons(stroke = FALSE,
# fillOpacity = 0.7,
# smoothFactor = 0.5,
# color = ~pal(Count),
# popup = ~Count)
tmap view COUNT
tmap_mode("view")
## tmap mode set to interactive viewing
manuCP <- tm_shape(join1) +
tm_polygons("Count",
style="jenks",
palette="PuBuGn",
alpha = 0.6,
title="Manufacturing Count. per LSOA",
border.col = "white",
lwd=0.5) +
tm_basemap(server="Esri.WorldImagery")
manuCP
tmap two polygons layers
manu2 <- tm_shape(join1) +
tm_polygons(c("Count", "choice2kmrank"),
style="jenks",
palette=list("PuBuGn","-RdYlBu"),
alpha = 0.6,
title=c("Count","2kmchoice"),
border.col = "white",
lwd=0.5) +
tm_basemap(server="Esri.WorldImagery") +
tm_facets(as.layers = TRUE)
manu2